//action对象包含业务操作todo逻辑方法
export default function (state) {
  const onAddTodo = (todo) => {
    state.todoList.push(todo);
    addCount();
  };

  const onToggleTodo = (id) => {
    state.todoList = state.todoList.map((item) => {
      item.id === id && (item.completed = !item.completed);
      return item;
    });
  };

  const onRemoveTodo = (id) => {
    state.todoList = state.todoList.filter((item) => item.id !== id);
    removeCount();
  };

  const addCount = () => {
    state.addCount++;
  };

  const removeCount = () => {
    state.removeCount++;
  };

  return {
    onAddTodo,
    onToggleTodo,
    onRemoveTodo
  };
}
